from setux.core.package import CommonPackager
from setux.logger import debug, info, error


# pylint: disable=no-member


class Arch(CommonPackager):
    manager = 'yay'

    pkgmap = dict(
        kicad    = 'org.kicad_pcb.KiCad',
        freecad  = 'org.freecadweb.FreeCAD',
        openscad = 'org.openscad.OpenSCAD',
    )

    def do_init(self):
        self.run(f'pacman -Sq --noconfirm yay')

    def do_install(self, pkg, ver=None):
        ret, out, err = self.run(f'yay -S --needed --noconfirm {pkg}')
        if err:
            msg = '\n'.join(err)
            debug(msg) if ret==0 else error(msg)

    def do_remove(self, pkg):
        self.run(f'yay -Rns {pkg}')

    def do_cleanup(self):
        self.run('yay -Yc')

    def do_update(self):
        debug('not implemented, use pacman')

    def ls(self):
        debug('not implemented, use pacman')

    def do_installed(self):
        debug('not implemented, use pacman')

    def do_installable(self):
        debug('not implemented, use pacman')


